﻿using FoodModel;
using J.FoodManageGet.Application.Command.SpecificationCommand;
using J.FoodRepository.InterFace;
using MediatR;

namespace J.FoodManageGet.Application.CommandHandler.SpecificationCommandHandler
{
    public class SpecificationclassifyCommandHandler : IRequestHandler<SpecificationclassifyCommand, List<SpecificationModel>>
    {
        private readonly ISpecificationRepository _specificationRepository;

        public SpecificationclassifyCommandHandler(ISpecificationRepository specificationRepository)
        {
            _specificationRepository = specificationRepository;
        }
        public async Task<List<SpecificationModel>> Handle(SpecificationclassifyCommand request, CancellationToken cancellationToken)
        {
            var list = await _specificationRepository.Specificationclassify();
            
            if (request.SpecificationId != 0)
            {
                list = list.Where(x => x.SpecificationId == request.SpecificationId).ToList();
            }
            return list; 
        }
    }
}
